package com.huffman.smart_picture.domain.vo.user;

import com.huffman.smart_picture.common.UserSession;
import com.huffman.smart_picture.domain.entity.User;
import com.huffman.smart_picture.domain.enums.UserVipEnum;
import lombok.Data;

import java.util.Date;
import java.util.Map;

/**
 * @author DengLin
 * @title 用户信息响应体
 * @date 2024/07/03
 */
@Data
public class UserVo {
    private Long id;
    private String username;
    private String nickname;
    private String avatar;
    private String phone;
    private String email;
    private String role;
    private Integer status;
    private Long expireTime;
    private Date createTime;
    private Boolean isVip = false;
    private Date vipExpireTime;
    private Long vipNumber;
    private Integer pictureCount = 0;
    private Integer fansCount = 0;
    private Integer followCount = 0;
    private Map<Long, Integer> spaceUserRoleMap;

    public static UserVo convert(User user) {
        UserVo userVo = new UserVo();
        userVo.setId(user.getId());
        userVo.setUsername(user.getUsername());
        userVo.setNickname(user.getNickname());
        userVo.setAvatar(user.getAvatar());
        userVo.setPhone(user.getPhone());
        userVo.setEmail(user.getEmail());
        userVo.setRole(user.getRole());
        userVo.setCreateTime(user.getCreateTime());
        userVo.setStatus(user.getStatus());
        if (user.getVipExpireTime() != null && user.getVipExpireTime().after(new Date())) {
            userVo.setIsVip(UserVipEnum.VIP.getValue().equals(user.getIsVip()));
        }else{
            userVo.setIsVip(false);
        }
        userVo.setVipNumber(user.getVipNumber());
        userVo.setVipExpireTime(user.getVipExpireTime());
        return userVo;
    }

    public static UserVo convert(UserSession user) {
        UserVo userVo = new UserVo();
        userVo.setId(user.getId());
        userVo.setUsername(user.getUsername());
        userVo.setNickname(user.getNickname());
        userVo.setAvatar(user.getAvatar());
        userVo.setRole(user.getRole());
        userVo.setExpireTime(user.getExpireTime());
        userVo.setSpaceUserRoleMap(user.getSpaceUserRoleMap());
        return userVo;
    }
}
